import { defineStore } from 'pinia'
import { getTargetDetail } from '@/common/http/module/plan'
import { currencyList } from '@/common/constant/plan'
import { useUserStore } from '@/store/user'

const userStore = useUserStore()

export const usePlanStore = defineStore('plan', {
  state: () => ({
    target: '',
    year: new Date().getFullYear()
  }),
  actions: {
    changeYear(val) {
      this.year = val
    },
    loadTarget() {
      getTargetDetail(userStore.currentSocietyId, this.year).then(res => {
        this.target = res.data
      })
    }
  },
  getters: {
    targetId: state => state.target?.id,
    currency: state => currencyList.find(item => item.value == state.target?.currency)
  }
})